package com.linght.SpringBoot;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StreamUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Description:
 * User:岁亮亮
 * Date:2024-11-07
 * TIME:10:29
 */

@RequestMapping("/user")
@RestController
public class LoginCOntroller {
    @RequestMapping("/login")
    public Boolean login(String username, String password, HttpSession session) {
        //判断传过来的参数是否为空或长度为0;
       /* if(!(username != null && username.length()!= 0 && password != null && password.length()!= 0)) {
            return false;
        }*/
        if(!(StringUtils.hasLength(username) && StringUtils.hasLength(password))){
            return false;
        }
        //进行校.验 看传过来的用户名和密码是否正确
        if("sll".equals(username) && "123456".equals(password)){
            session.setAttribute("username", username);
            session.setAttribute("password", password);
            return true;
        }
        return false;

    }
    @RequestMapping("/index")
    public String index(HttpSession session){
        String username = (String) session.getAttribute("username");
        return username;
    }
    @RequestMapping("/password")
    public String password(HttpSession session){
        String password = (String) session.getAttribute("password");
        return password;
    }
}
